/*
 * QIconAdapter.h  0.4.0 / Nov 17, 2010
 *
 * Copyright (c) 2010 - 2011, cute4j.com and contributors.
 *
 * This software is licensed under the LGPL version 2.1 license.
 * A copy of this license is included in the file LICENSE-LGPL.txt.
 */
#ifndef QICONADAPTER_H
#define QICONADAPTER_H

#include "Cute4jSwing.h"

#include "SwingGraphics.h"

// QIconAdapter Class. ---------------------------------------------------------

/*!
 * \brief QIcon Adapter.
 *
 * \author Slobodan Vrkacevic
 * \version 0.4.0
 */
class CUTE4J_EXPORT QIconAdapter : public QIcon
{
public:
  enum IconType { DefaultIcon, PressedIcon, SelectedIcon, DisabledIcon,
                  DisabledSelectedIcon, RolloverIcon, RolloverSelectedIcon };
public:
  QIconAdapter(JNIEnv *env, jobject iconSet);
  QIconAdapter(JNIEnv *env, jobject iconSet, IconType *m_iconType);
};

// QIconAdapterEngine Class. ---------------------------------------------------

/*!
 * \brief QIconEngine implementation.
 *
 * \author Slobodan Vrkacevic
 * \version 0.4.0
 */
class QIconAdapterEngine : public QIconEngine
{
public:
  QIconAdapterEngine(JNIEnv *env, jobject iconSet);
  QIconAdapterEngine(JNIEnv *env, jobject iconSet,
                     QIconAdapter::IconType *m_iconType);
  virtual ~QIconAdapterEngine();
public:
  void setIcon(QPixmap *image);
  void setPressedIcon(QPixmap *image);
  void removePressedIcon();
  void setSelectedIcon(QPixmap *image);
  void removeSelectedIcon();
  void setDisabledIcon(QPixmap *image);
  void removeDisabledIcon();
  void setDisabledSelectedIcon(QPixmap *image);
  void removeDisabledSelectedIcon();
  void setRolloverIcon(QPixmap *image);
  void removeRolloverIcon();
  void setRolloverSelectedIcon(QPixmap *image);
  void removeRolloverSelectedIcon();
public:
  QSize actualSize(const QSize &size, QIcon::Mode, QIcon::State);
  QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state);
  void paint(QPainter *painter, const QRect &rect, QIcon::Mode,
             QIcon::State state);
  void addFile(const QString &str, const QSize &size,  QIcon::Mode,
               QIcon::State);
  void addPixmap(const QPixmap &pm, QIcon::Mode, QIcon::State state);
public:
  static void initialize(JNIEnv *env, jclass cls);
private:
  QIconAdapter::IconType iconType(QIcon::Mode mode, QIcon::State state);
  void makeDisabledIcon();
  jint getWidth(jint type);
  jint getHeight(jint type);
  bool isDisabledIconSet();
private:
  jobject m_iconSet;
  QPixmap *m_icons[7];
  QIconAdapter::IconType *m_iconType;
  bool m_makeDisabledIcon;
  bool m_disabledIconGenerated;
private:
  static jfieldID sm_iconEnginePointerFID;
  static jmethodID sm_getIconWidthMID;
  static jmethodID sm_getIconHeightMID;
  static jmethodID sm_paintIconMID;
};

// Macro Definitions. ----------------------------------------------------------

#define qIconAdapterEngine \
    (reinterpret_cast<QIconAdapterEngine *>(iconEnginePointer))

#define qIconImage (reinterpret_cast<QPixmap *>(imagePointer))

#endif // QICONADAPTER_H

